# -*- coding: utf-8 -*-
# created by Src - 一路好时光

#
names=['alex', 'jack']
print(names)#['alex', 'jack']
names.append("src")
print(names)#['alex', 'jack', 'src']
names.insert(2, "黑姑娘")
print(names)#['alex', 'jack', '黑姑娘', 'src']
n2=["aa","bb","cc"]
print(n2)#['aa', 'bb', 'cc']
names.extend(n2)
print(names)#['alex', 'jack', '黑姑娘', 'src', 'aa', 'bb', 'cc']
names.insert(2,["shi","rui"])
#列表嵌套
print(names)#['alex', 'jack', ['shi', 'rui'], '黑姑娘', 'src', 'aa', 'bb', 'cc']
print(names[2])#['shi', 'rui']
print(names[2][1])#rui
names[2][1]="chao"
print(names)#['alex', 'jack', ['shi', 'chao'], '黑姑娘', 'src', 'aa', 'bb', 'cc']
print(names.pop())#cc
deleted_item = names.pop()
print(deleted_item)#bb
print(names)#['alex', 'jack', ['shi', 'chao'], '黑姑娘', 'src', 'aa']
print(names.pop(-2))#src
print(names)#['alex', 'jack', ['shi', 'chao'], '黑姑娘', 'aa']
names.remove("jack")
print(names)#['alex', ['shi', 'chao'], '黑姑娘', 'aa']
print(n2)#['aa', 'bb', 'cc']
n2.clear()
print(n2)#[]

print(names.index("黑姑娘"))#2
print(names.count("alex"))#1

print(names)#['alex', ['shi', 'chao'], '黑姑娘', 'aa']
print("aa" in names)#True


#切片
n=['alex', 'jack', ['shi', 'chao'], '黑姑娘', 'aa']
print(n)#['alex', 'jack', ['shi', 'chao'], '黑姑娘', 'aa']
print(n[1:4])#['jack', ['shi', 'chao'], '黑姑娘']
print(n[0:4])#['alex', 'jack', ['shi', 'chao'], '黑姑娘']
#简写，可以去掉0
print(n[:4])#['alex', 'jack', ['shi', 'chao'], '黑姑娘']
print(n[3:4])#['黑姑娘']
#python3，超过索引也不会出错
print(n[3:5])#['黑姑娘', 'aa']
print(n[3:8])#['黑姑娘', 'aa']
#省略写法
print(n[3:])#['黑姑娘', 'aa']
#从左向右切
print(n[-3:-1])#[['shi', 'chao'], '黑姑娘']
print(n[-1:-3])#[]
print(n[-3:])#[['shi', 'chao'], '黑姑娘', 'aa']


#步长 默认1
print(n)#['alex', 'jack', ['shi', 'chao'], '黑姑娘', 'aa']
print(n[0:-1])#['alex', 'jack', ['shi', 'chao'], '黑姑娘']
print(n[0:])#['alex', 'jack', ['shi', 'chao'], '黑姑娘', 'aa']
print(n[0:-1:1])#['alex', 'jack', ['shi', 'chao'], '黑姑娘']
print(n[0:-1:2])#['alex', ['shi', 'chao']]
#省略写法
print(n[0::2])#['alex', ['shi', 'chao'], 'aa']
print(n[::2])#['alex', ['shi', 'chao'], 'aa']

#排序
n=['alex', 'jack', ['shi', 'chao'], '黑姑娘', 'aa']
print(n)#['alex', 'jack', ['shi', 'chao'], '黑姑娘', 'aa']
#n.sort()#会报错，里面有列表[] TypeError: '<' not supported between instances of 'list' and 'str'
del n[2]
print(n)#['alex', 'jack', '黑姑娘', 'aa']
n.sort()#排序  自然序
print(n)#['aa', 'alex', 'jack', '黑姑娘']
n[2]="Alex"
print(n)#['aa', 'alex', 'Alex', '黑姑娘']
n.sort()
print(n)#['Alex', 'aa', 'alex', '黑姑娘']

n2=[4,2,3,5,2,5,6,3,67,8,9]
n2.sort()
print(n2)#[2, 2, 3, 3, 4, 5, 5, 6, 8, 9, 67]
n2.reverse()
print(n2)#[67, 9, 8, 6, 5, 5, 4, 3, 3, 2, 2]

#循环
for j in n2:
    print(j)
# 67
# 9
# 8
# 6

#打印索引  (0, 'Alex')元祖
for i in enumerate(n):
    print(i)
# (0, 'Alex')
# (1, 'aa')
# (2, 'alex')
# (3, '黑姑娘')

#打印元祖
for i in enumerate(n):
    print(i[0],i[1])
#0 Alex
# 1 aa
# 2 alex
# 3 黑姑娘

